<?php
use think\facade\Route;
use think\facade\Request;
$baseUrl = Request::baseUrl();
if(isset($baseUrl) and !empty($baseUrl)){
	if(strrpos($baseUrl,'?')){
		$baseUrl = strstr($baseUrl);
	}
    $uto = explode('/', $baseUrl);
	$utos = $uto;
	if(is_numeric(end($uto))){
		array_pop($uto);
        $urlParam = substr($baseUrl,0,strrpos($baseUrl, '/'));
	}elseif(count($uto) > 2){
		$urlParam = $baseUrl;
	}else{
		$urlParam = end($uto);
	}
	$where['cat.controller'] = end($uto);
	$PortalCat = think\facade\Db::name('portal_category')
	->alias('cat')
	->join('cmm_arctype arc','cat.temp_ip = arc.id')
	->field('cat.id,cat.controller,arc.nid')
	->where($where)
	->find();
	if(!empty($PortalCat)){
	    Route::get($urlParam.'/:id', 'portal/View/index')
	    ->append(array('cid' => $PortalCat['id']));
          
	    Route::get($urlParam,'portal/'.$PortalCat['nid'].'/index')
	    ->append(array('id' => $PortalCat['id']))
	    ->pattern(array('id' => '\d+',  'cid' => '\d+',));
	}

}


